package com.tsx.demo;

import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.AreaBreak;
import com.itextpdf.layout.element.Paragraph;

import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Demo3 {
    public static void main(String[] args) {
        String para1 = "This is para1";
        String para2 = "This is para2";
        Path path = Paths.get(Constants.dest, "demo3.pdf");
        try (OutputStream os = Files.newOutputStream(path)) {
            PdfWriter pdfWriter = new PdfWriter(os);
            PdfDocument pdfDocument = new PdfDocument(pdfWriter);
            Document document = new Document(pdfDocument);
            Paragraph paragraph1 = new Paragraph(para1);
            Paragraph paragraph2 = new Paragraph(para2);
            document.add(paragraph1);
            document.add(new AreaBreak());
            document.add(paragraph2);
            document.close();
            pdfDocument.close();
            pdfWriter.close();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
